#include "queue.h"


//创建队列
queue_t* create_queue(void){
    queue_t *p = (queue_t*)calloc(1,sizeof(queue_t));
    ERROR_CHECK(p, NULL, "calloc_queue_error");
    return p;
}

//出队
int quit_queue(queue_t *p){
    if(p->size == 0){
        printf("队列为空!\n");
        return 0;
    }
    node_t *curr = p->front;
    p->front = curr->next;
    if(p->front == NULL){
        p->rear = NULL;
    }
    p->size--;
    free(curr);
    return 0;
}          
    
//入队
int add_queue(queue_t *p, int val){
    node_t *new_node = (node_t *)calloc(1, sizeof(node_t));
    ERROR_CHECK(new_node, NULL, "calloc_node_error");
    new_node->data = val;
    new_node->next = NULL;
    if(p->size == 0){
        p->front = new_node;
        p->rear = new_node;
        p->size++;
        return 0;
    }
    p->rear->next = new_node;
    p->rear = new_node;
    p->size++;
    return 0;
    
}

